﻿

app.controller('CalcAnalysisController', function ($scope, $http, $window, $compile, $filter, ipCookie, common, option, Upload) {
    $scope.result = {};
    $scope.dateOption = option.date;
    $scope.datetimeOption = option.datetime;

    $scope.InitDatePicker = function (control) {
        (function ($) {
            $.init();
            var btns = $(control);
            btns.each(function (i, btn) {
                btn.addEventListener('tap', function () {
                    var _self = this;
                    if (_self.picker) {
                        _self.picker.show(function (rs) {
                            jQuery(control).val(rs.text);
                            _self.picker.dispose();
                            _self.picker = null;
                        });
                    } else {
                        var optionsJson = this.getAttribute('data-options') || '{}';
                        var options = JSON.parse(optionsJson);
                        var id = this.getAttribute('id');
                        _self.picker = new $.DtPicker(options);
                        _self.picker.show(function (rs) {
                            jQuery(control).val(rs.text);
                            console.log($scope.AddModel);
                            _self.picker.dispose();
                            _self.picker = null;
                        });
                    }
                }, false);
            });
        })(mui);
    }

    $scope.GetCheckYearList = function () {
        $http({
            method: 'POST',
            url: '../Home/GetCheckYearList'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.CheckYearList = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetCheckNum = function () {
        $scope.CheckCount = [];
        $http({
            method: 'POST',
            url: '../Home/GetCheckRecordCount'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.CheckCount = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });

        $scope.IssueCount = [];
        $http({
            method: 'POST',
            url: '../Home/GetHiddenTroubleRecordCount'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.IssueCount = ret.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetCheckCountView = function (model) {
        if (model.Type == 1) {
            $scope.GetDepartmentCheckChart(model);
        }
        else if (model.Type == 2) {
            $scope.GetMonthCheckChart(model.Year);
        }
        else {
            $scope.GetPlaceCheckChart(model);
        }
    }

    $scope.GetMonthCheckChart = function (year) {
        $http({
            method: 'POST',
            url: '../Home/GetMonthCheckChart',
            data: { "Year": year }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var datalist = ret.Data;
                    var namelist = [];
                    var total = [];
                    var normal = [];
                    var exception = [];
                    for (var i = 0; i < datalist.length; i++) {
                        namelist.push(datalist[i].Name);
                        total.push(datalist[i].Total);
                        normal.push(datalist[i].Normal);
                        exception.push(datalist[i].ExCount);
                    }
                    var myChart = echarts.init(document.getElementById('countview'));
                    var option = {
                        legend: {},
                        tooltip: {},
                        toolbox: {
                            show: true,
                            orient: 'vertical',
                            left: 'right',
                            top: 'center',
                            feature: {
                                mark: { show: true },
                                magicType: { show: true, type: ['line', 'bar', 'stack'] },
                                restore: { show: true },
                                saveAsImage: { show: true }
                            }
                        },
                        xAxis: {
                            type: 'category',
                            data: namelist,//['系统实施BU', '后勤保障共享中心', '质量审核部', '采购共享中心', '用户支持BU', '工业工程部', '财务共享中心', '标推化部', '需求架构BU', '生产与运营支持', '审计部'],
                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1
                                }
                            },
                            axisLine: {
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1,
                                }
                            },
                            axisLabel: {
                                show: true,
                                textStyle: {
                                    color: 'rgba(122, 144, 154)'   //这里用参数代替了
                                }
                            }

                        },
                        yAxis: {

                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1
                                }
                            }
                        },
                        grid:
                        {
                            bottom: 20,
                            top: 20,
                            left: 30,
                            right: 25
                        },

                        series: [
                            //{
                            //    name: '计划',
                            //    type: 'bar',
                            //    itemStyle: {
                            //        color: 'rgba(135, 153, 154, 0.7)',
                            //        borderWidth: 0.5,
                            //        borderColor: "rgba(135, 153, 154)",
                            //    },
                            //    data: total//[43, 52, 65, 53, 55, 27, 44, 62, 42, 54, 59]
                            //},
                            {
                                name: '正常',
                                type: 'bar',
                                stack: "ad",
                                itemStyle: {
                                    color: 'rgba(168, 228, 223, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(168, 228, 223)",

                                },
                                data: normal// [25, 23, 31, 37, 28, 4, 25, 57, 29, 31, 45]
                            },
                            {
                                name: '异常',
                                type: 'bar',
                                stack: "ad",
                                itemStyle: {
                                    color: 'rgba(250, 219, 216, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(250, 219, 216)",
                                },
                                data: exception//[11, 20, 13, 12, 11, 1, 5, 17, 7, 13, 25, 14]
                            }
                        ]
                    };
                    myChart.setOption(option, true);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }
    $scope.GetPlaceCheckChart = function (model) {
        $http({
            method: 'POST',
            url: '../Home/GetPlaceCheckChart',
            data: { "Year": model.Year, "Month": model.Month, "PlaceType": model.PlaceType }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var datalist = ret.Data;
                    var namelist = [];
                    var total = [];
                    var normal = [];
                    var exception = [];
                    for (var i = 0; i < datalist.length; i++) {
                        namelist.push(datalist[i].Name);
                        total.push(datalist[i].Total);
                        normal.push(datalist[i].Normal);
                        exception.push(datalist[i].ExCount);
                    }
                    var myChart = echarts.init(document.getElementById('countview'));
                    var option = {
                        legend: {},
                        tooltip: {},
                        toolbox: {
                            show: true,
                            orient: 'vertical',
                            left: 'right',
                            top: 'center',
                            feature: {
                                mark: { show: true },
                                magicType: { show: true, type: ['line', 'bar', 'stack'] },
                                restore: { show: true },
                                saveAsImage: { show: true }
                            }
                        },
                        xAxis: {
                            type: 'category',
                            data: namelist,//['系统实施BU', '后勤保障共享中心', '质量审核部', '采购共享中心', '用户支持BU', '工业工程部', '财务共享中心', '标推化部', '需求架构BU', '生产与运营支持', '审计部'],
                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1
                                }
                            },
                            axisLine: {
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1,
                                }
                            },
                            axisLabel: {
                                interval: 0,
                                rotate: 12,
                                show: true,
                                textStyle: {
                                    color: 'rgba(122, 144, 154)'   //这里用参数代替了
                                }
                            }

                        },
                        yAxis: {

                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1
                                }
                            }
                        },
                        grid:
                        {
                            bottom: 40,
                            top: 20,
                            left: 30,
                            right: 25
                        },

                        series: [
                            //{
                            //    name: '计划',
                            //    type: 'bar',

                            //    itemStyle: {
                            //        color: 'rgba(135, 153, 154, 0.7)',
                            //        borderWidth: 0.5,
                            //        borderColor: "rgba(135, 153, 154)",
                            //    },
                            //    data: total//[43, 52, 65, 53, 55, 27, 44, 62, 42, 54, 59]
                            //},
                            {
                                name: '正常',
                                type: 'bar',
                                stack: "ad",
                                itemStyle: {
                                    color: 'rgba(168, 228, 223, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(168, 228, 223)",

                                },
                                data: normal// [25, 23, 31, 37, 28, 4, 25, 57, 29, 31, 45]
                            },
                            {
                                name: '异常',
                                type: 'bar',
                                stack: "ad",
                                itemStyle: {
                                    color: 'rgba(250, 219, 216, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(250, 219, 216)",
                                },
                                data: exception//[11, 20, 13, 12, 11, 1, 5, 17, 7, 13, 25, 14]
                            }
                        ]
                    };
                    myChart.setOption(option, true);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetMonthlyCheckChart = function (model) {
        $http({
            method: 'POST',
            url: '../Home/GetCheckRecordByType',
            data: { 'PlaceType': model.PlaceType2 }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var datalist = ret.Data;
                    var namelist = [];
                    var dailycount = [];
                    var weeklycount = [];
                    var monthlycount = [];
                    var exceptioncount = [];
                    for (var i = 0; i < datalist.length; i++) {
                        namelist.push(datalist[i].date);
                        dailycount.push(datalist[i].dailycount);
                        weeklycount.push(datalist[i].weeklycount);
                        monthlycount.push(datalist[i].monthlycount);
                        exceptioncount.push(datalist[i].exceptioncount);
                    }
                    var myChart = echarts.init(document.getElementById('checkrecordmonthlyview'));
                    var option = {
                        legend: {},
                        tooltip: {},
                        toolbox: {
                            show: true,
                            orient: 'vertical',
                            left: 'right',
                            top: 'center',
                            feature: {
                                mark: { show: true },
                                magicType: { show: true, type: ['line', 'bar', 'stack'] },
                                restore: { show: true },
                                saveAsImage: { show: true }
                            }
                        },
                        xAxis: {
                            type: 'category',
                            inverse: true,
                            data: namelist,//['系统实施BU', '后勤保障共享中心', '质量审核部', '采购共享中心', '用户支持BU', '工业工程部', '财务共享中心', '标推化部', '需求架构BU', '生产与运营支持', '审计部'],
                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1
                                }
                            },
                            axisLine: {
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1,
                                }
                            },
                            axisLabel: {
                                interval: 0,
                                rotate: 12,
                                show: true,
                                textStyle: {
                                    color: 'rgba(122, 144, 154)'   //这里用参数代替了
                                }
                            }

                        },
                        yAxis: {

                            splitLine: {
                                show: true,
                                lineStyle: {
                                    color: 'rgba(0, 0, 0, 0.06)',
                                    width: 1
                                }
                            }
                        },
                        grid:
                        {
                            bottom: 40,
                            top: 20,
                            left: 30,
                            right: 25
                        },

                        series: [
                            {
                                name: '日检',
                                smooth: true,
                                type: 'line',
                                label: {
                                    show: true
                                },
                                //stack: "ad",
                                itemStyle: {
                                    color: 'rgba(83, 148, 201, 0.7)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(83, 148, 201)",
                                },
                                data: dailycount
                            },
                            {
                                name: '周检',
                                smooth: true,
                                type: 'line',
                                //stack: "ad",
                                itemStyle: {
                                    color: 'rgba(168, 228, 223, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(168, 228, 223)",

                                },
                                data: weeklycount
                            },
                            {
                                name: '月检',
                                smooth: true,
                                type: 'line',
                                //stack: "ad",
                                itemStyle: {
                                    color: 'rgba(145, 201, 117, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(145, 201, 117)",
                                },
                                data: monthlycount
                            },
                            {
                                name: '异常项',
                                smooth: true,
                                type: 'line',
                                //stack: "ad",
                                itemStyle: {
                                    color: 'rgba(229, 63, 49, 0.6)',
                                    borderWidth: 0.5,
                                    borderColor: "rgba(229, 63, 49)",
                                },
                                data: exceptioncount
                            }
                        ]
                    };
                    myChart.setOption(option);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetCategoryView = function (model) {
        $http({
            method: 'POST',
            url: '../Home/GetCategoryView',
            data: { "Year": model.Year }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                var datalist = ret.Data;
                var myChart = echarts.init(document.getElementById('typeview'));
                var option = {
                    title: {
                        show: false,
                        text: 'Referer of a Website',
                        subtext: 'Fake Data',
                        left: 'center'
                    },
                    tooltip: {
                        trigger: 'item'
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left'
                    },
                    series: [
                        {
                            name: '问题类型分布',
                            type: 'pie',
                            center: ['60%', '50%'],
                            radius: '50%',
                            data: datalist,
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                myChart.setOption(option);

            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetParkView = function (model) {
        $http({
            method: 'POST',
            url: '../Home/GetParkView',
            data: { "Year": model.Year }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                var datalist = ret.Data;
                var myChart = echarts.init(document.getElementById('factoryview'));
                var option = {
                    tooltip: {
                        trigger: 'item'
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left'
                    },
                    series: [
                        {
                            name: '园区分布图',
                            type: 'pie',
                            radius: ['40%', '70%'],
                            avoidLabelOverlap: false,
                            label: {
                                show: false,
                                position: 'center'
                            },
                            emphasis: {
                                label: {
                                    show: true,
                                    fontSize: '40',
                                    fontWeight: 'bold'
                                }
                            },
                            labelLine: {
                                show: false
                            },
                            color: ['rgb(83,148,201)', 'rgb(55,191,141)', 'orange', 'grey'],
                            data: datalist
                        }
                    ]
                };
                myChart.setOption(option);

            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetLevelView = function (model) {
        $http({
            method: 'POST',
            url: '../Home/GetLevelView',
            data: { "Year": model.Year }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                var datalist = ret.Data;
                var myChart = echarts.init(document.getElementById('souceview'));
                var option = {
                    title: {
                        show: false,
                        text: 'Referer of a Website',
                        subtext: 'Fake Data',
                        left: 'center'
                    },
                    tooltip: {
                        trigger: 'item'
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left'
                    },
                    series: [
                        {
                            name: '问题等级分布',
                            type: 'pie',
                            center: ['60%', '50%'],
                            radius: '50%',
                            data: datalist,
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                myChart.setOption(option);

            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetPlaceCountByType = function () {
        $http({
            method: 'POST',
            url: '../Home/GetPlaceCountByType'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var myChart = echarts.init(document.getElementById('placetypeview'));

                    var datalist = ret.Data;

                    var option = {
                        tooltip: {
                            trigger: 'item'
                        },
                        legend: {
                            orient: 'vertical',
                            left: 'left'
                        },
                        toolbox: {
                            show: true,
                            orient: 'vertical',
                            left: 'right',
                            top: 'center',
                            feature: {
                                saveAsImage: { show: true }
                            }
                        },
                        series: [
                            {
                                name: '',
                                type: 'pie',
                                radius: ['40%', '70%'],
                                label: {
                                    alignTo: 'labelLine',
                                    formatter: '{name|{b}}{c}个  占{d}%',
                                    minMargin: 5,
                                    edgeDistance: 3,
                                    lineHeight: 15,
                                    rich: {
                                        time: {
                                            fontSize: 10,
                                            color: '#999'
                                        }
                                    }
                                },
                                labelLine: {
                                    show: true
                                },
                                data: datalist,
                                itemStyle: {
                                    normal: {
                                        color: function (params) {
                                            var colorList = [
                                                '#FF6666', '#FFCC33', '#0E5DA6', '#00E5AB', '#0E5DA6', '#1177DC'
                                            ];
                                            return colorList[params.dataIndex]
                                        }
                                    }
                                }
                            }
                        ]
                    };
                    myChart.setOption(option);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });

    }

    $scope.MGetPlaceCountByType = function () {
        $http({
            method: 'POST',
            url: '../Home/GetPlaceCountByType'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var myChart = echarts.init(document.getElementById('placetypeview'));

                    var datalist = ret.Data;

                    var option = {
                        tooltip: {
                            trigger: 'item'
                        },
                        legend: {
                            orient: 'vertical',
                            left: 'left',
                            show: false
                        },
                        toolbox: {
                            show: false,
                            orient: 'vertical',
                            left: 'right',
                            top: 'center',
                            feature: {
                                saveAsImage: { show: true }
                            }
                        },
                        series: [
                            {
                                name: '',
                                type: 'pie',
                                radius: ['20%', '50%'],
                                label: {
                                    alignTo: 'labelLine',
                                    formatter: '{name|{b}}{c}个',
                                    minMargin: 5,
                                    edgeDistance: 3,
                                    lineHeight: 15,
                                    rich: {
                                        time: {
                                            fontSize: 10,
                                            color: '#999'
                                        }
                                    }
                                },
                                labelLine: {
                                    show: true
                                },
                                data: datalist,
                                itemStyle: {
                                    normal: {
                                        color: function (params) {
                                            var colorList = [
                                                '#FF6666', '#FFCC33', '#0E5DA6', '#00E5AB', '#0E5DA6', '#1177DC'
                                            ];
                                            return colorList[params.dataIndex]
                                        }
                                    }
                                }
                            }
                        ]
                    };
                    myChart.setOption(option);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });

    }

    $scope.GetPlaceCountByPark = function () {
        $http({
            method: 'POST',
            url: '../Home/GetPlaceCountByPark'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var myChart = echarts.init(document.getElementById('parkplaceview'));
                    var datalist = [];
                    for (var i = 0; i < ret.Data.length; i++) {
                        var data = ret.Data[i];
                        var obj = {
                            'name': data.ParkName,
                            'value': data.PlaceNum
                        };
                        datalist.push(obj);
                    }

                    var option = {
                        title: {
                            show: false,
                        },
                        tooltip: {
                            trigger: 'item'
                        },
                        show: true,
                        orient: 'vertical',
                        left: 'right',
                        top: 'center',
                        feature: {
                            saveAsImage: { show: true }
                        },
                        legend: {
                            orient: 'vertical',
                            left: 'left'
                        },
                        series: [
                            {
                                label: {
                                    alignTo: 'labelLine',
                                    formatter: '{name|{b}}{c}个  占{d}%',
                                    minMargin: 5,
                                    edgeDistance: 3,
                                    lineHeight: 15,
                                    rich: {
                                        time: {
                                            fontSize: 10,
                                            color: '#999'
                                        }
                                    }
                                },
                                name: '',
                                type: 'pie',
                                center: ['60%', '50%'],
                                radius: '70%',
                                data: datalist,
                                emphasis: {
                                    itemStyle: {
                                        shadowBlur: 10,
                                        shadowOffsetX: 0,
                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                                    }
                                }
                            }
                        ]
                    };
                    myChart.setOption(option);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.MGetPlaceCountByPark = function () {
        $http({
            method: 'POST',
            url: '../Home/GetPlaceCountByPark'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var myChart = echarts.init(document.getElementById('parkplaceview'));
                    var datalist = [];
                    for (var i = 0; i < ret.Data.length; i++) {
                        var data = ret.Data[i];
                        var obj = {
                            'name': data.ParkName,
                            'value': data.PlaceNum
                        };
                        datalist.push(obj);
                    }

                    var option = {
                        title: {
                            show: false,
                        },
                        tooltip: {
                            trigger: 'item'
                        },
                        show: true,
                        orient: 'vertical',
                        left: 'right',
                        top: 'center',
                        feature: {
                            saveAsImage: { show: true }
                        },
                        legend: {
                            orient: 'vertical',
                            left: 'left',
                            show: false
                        },
                        series: [
                            {
                                label: {
                                    alignTo: 'labelLine',
                                    formatter: '{name|{b}}{c}个',
                                    minMargin: 5,
                                    edgeDistance: 3,
                                    lineHeight: 15,
                                    rich: {
                                        time: {
                                            fontSize: 10,
                                            color: '#999'
                                        }
                                    }
                                },
                                name: '',
                                type: 'pie',
                                center: ['50%', '50%'],
                                radius: '70%',
                                data: datalist,
                                emphasis: {
                                    itemStyle: {
                                        shadowBlur: 10,
                                        shadowOffsetX: 0,
                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                                    }
                                }
                            }
                        ]
                    };
                    myChart.setOption(option);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetDeviceCountByType = function () {
        $http({
            method: 'POST',
            url: '../Home/GetDeviceCountByType'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var myChart = echarts.init(document.getElementById('devicetypeview'));
                    var datalist = ret.Data;
                    var namelist = [];
                    var valuelist = [];
                    for (var i = 0; i < datalist.length; i++) {
                        var data = datalist[i];
                        valuelist.push(data.value);
                        namelist.push(data.name);
                    }
                    var option = {
                        title: {
                            text: ''
                        },
                        tooltip: {
                            trigger: 'axis',
                            axisPointer: {
                                type: 'shadow'
                            }
                        },
                        legend: { show: false },
                        grid: {
                            left: '3%',
                            right: '4%',
                            top: '3%',
                            bottom: '3%',
                            containLabel: true
                        },
                        xAxis: {
                            type: 'value',
                            boundaryGap: [0, 0.01]
                        },
                        yAxis: {
                            type: 'category',
                            data: namelist
                        },
                        series: [
                            {
                                name: '设备数量',
                                type: 'bar',
                                label: {
                                    show: true
                                },
                                data: valuelist,
                                itemStyle: {
                                    normal: {
                                        color: function (params) {
                                            var colorList = [
                                                '#FF6666', '#FFCC33', '#0E5DA6', '#00E5AB', '#FF9966'
                                            ];
                                            return colorList[params.dataIndex]
                                        }
                                    }
                                }
                            }
                        ]
                    };
                    myChart.setOption(option);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.MGetDeviceCountByType = function () {
        $http({
            method: 'POST',
            url: '../Home/GetDeviceCountByType'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    var myChart = echarts.init(document.getElementById('devicetypeview'));
                    var datalist = ret.Data;
                    var namelist = [];
                    var valuelist = [];
                    for (var i = 0; i < datalist.length; i++) {
                        var data = datalist[i];
                        valuelist.push(data.value);
                        namelist.push(data.name);
                    }
                    var option = {
                        title: {
                            text: ''
                        },
                        tooltip: {
                            trigger: 'axis',
                            axisPointer: {
                                type: 'shadow'
                            }
                        },
                        legend: { show: false },
                        grid: {
                            left: '3%',
                            right: '4%',
                            top: '3%',
                            bottom: '3%',
                            containLabel: true
                        },
                        xAxis: {
                            type: 'value',
                            boundaryGap: [0, 0.01]
                        },
                        yAxis: {
                            type: 'category',
                            data: namelist
                        },
                        series: [
                            {
                                name: '设备数量',
                                type: 'bar',
                                label: {
                                    show: true
                                },
                                data: valuelist,
                                itemStyle: {
                                    normal: {
                                        color: function (params) {
                                            var colorList = [
                                                '#FF6666', '#FFCC33', '#0E5DA6', '#00E5AB', '#FF9966'
                                            ];
                                            return colorList[params.dataIndex]
                                        }
                                    }
                                }
                            }
                        ]
                    };
                    myChart.setOption(option);
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetDailyCheckStatus = function (model) {
        $scope.CheckStatusList = {};
        if ($("#starttime").val() != "") {
            model.StartTime = $("#starttime").val();
        }
        if ($("#endtime").val() != "") {
            model.EndTime = $("#endtime").val();
        }
        console.log(model);
        $http({
            method: 'POST',
            url: '../CheckForm/GetDailyCheckStatus',
            data: { 'model': model }
        })
            .success(function (ret) {
                $scope.Loading = false;
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    var datalist = [];
                    $scope.CheckStatusList = ret.Data;
                    var daily = {
                        "name": "日检", "value": ret.Data.DailyCount
                    };
                    datalist.push(daily);

                    var weekly = {
                        "name": "周检", "value": ret.Data.WeeklyCount
                    };
                    datalist.push(weekly);

                    var monthly = {
                        "name": "月检", "value": ret.Data.MonthlyCount
                    };
                    datalist.push(monthly);

                    var exceptioncount = {
                        "name": "异常", "value": ret.Data.ExcepetionCount
                    };
                    datalist.push(exceptioncount);

                    var myChart = echarts.init(document.getElementById('checkchart'));


                    var option = {
                        tooltip: {
                            trigger: 'item'
                        },
                        legend: {
                            show: false,
                            orient: 'vertical',
                            left: 'left'
                        },
                        toolbox: {
                            show: false,
                            orient: 'vertical',
                            left: 'right',
                            top: 'center',
                            feature: {
                                saveAsImage: { show: true }
                            }
                        },
                        series: [
                            {
                                name: '',
                                type: 'pie',
                                radius: ['40%', '70%'],
                                label: {
                                    alignTo: 'labelLine',
                                    formatter: '{name|{b}}{c}次',
                                    minMargin: 5,
                                    edgeDistance: 3,
                                    lineHeight: 15,
                                    rich: {
                                        time: {
                                            fontSize: 10,
                                            color: '#999'
                                        }
                                    }
                                },
                                labelLine: {
                                    show: true
                                },
                                data: datalist,
                                itemStyle: {
                                    normal: {
                                        color: function (params) {
                                            var colorList = [
                                                '#00E5AB', '#FFCC33', '#0E5DA6', '#FF6666', '#0E5DA6', '#1177DC', '#FF6666'
                                            ];
                                            return colorList[params.dataIndex]
                                        }
                                    }
                                }
                            }
                        ]
                    };
                    myChart.setOption(option);
                    var dlist = ret.Data.DetailList;
                    
                    setTimeout(function () {
                        var myChart2 = echarts.init(document.getElementById('depchart'));
                        var namelist = [];
                        var dailylist = [];
                        var weeklylist = [];
                        var monthlylist = [];
                        var exlist = [];
                        for (var i = 0; i < dlist.length; i++) {
                            namelist.push(dlist[i].TypeName);
                            dailylist.push(dlist[i].DailyCount);
                            weeklylist.push(dlist[i].WeeklyCount);
                            monthlylist.push(dlist[i].MonthlyCount);
                            exlist.push(dlist[i].ExcepetionCount);
                        }
                        var option2 = {
                            tooltip: {
                                trigger: 'axis',
                                axisPointer: {
                                    // Use axis to trigger tooltip
                                    type: 'shadow' // 'shadow' as default; can also be 'line' or 'shadow'
                                }
                            },
                            legend: { show: false },
                            grid: {
                                left: '3%',
                                right: '4%',
                                bottom: '3%',
                                containLabel: true
                            },
                            xAxis: {
                                type: 'value',
                                splitline: false,
                                minInterval: 1
                            },
                            yAxis: {
                                type: 'category',

                                data: namelist//['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
                            },
                            series: [
                                {
                                    name: '日检',
                                    type: 'bar',
                                    stack: 'total',
                                    label: {
                                        show: false
                                    },
                                    itemStyle: {
                                        color: '#33CCCC',
                                    },
                                    emphasis: {
                                        focus: 'series'
                                    },
                                    data: dailylist
                                },
                                {
                                    name: '周检',
                                    type: 'bar',
                                    stack: 'total',
                                    label: {
                                        show: false
                                    },
                                    itemStyle: {
                                        color: '#FFCC33',
                                    },
                                    emphasis: {
                                        focus: 'series'
                                    },
                                    data: weeklylist
                                },
                                {
                                    name: '月检',
                                    type: 'bar',
                                    stack: 'total',
                                    label: {
                                        show: false
                                    },
                                    itemStyle: {
                                        color: '#0E5DA6',
                                    },
                                    emphasis: {
                                        focus: 'series'
                                    },
                                    data: monthlylist
                                },
                                {
                                    name: '异常',
                                    type: 'bar',
                                    stack: 'exception',
                                    label: {
                                        show: false
                                    },
                                    itemStyle: {
                                        color: '#FF6666',
                                    },
                                    emphasis: {
                                        focus: 'series'
                                    },
                                    data: exlist
                                }
                            ]
                        };
                        myChart2.resize();
                        myChart2.setOption(option2);
                    }, 1000);
                }
                else {

                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetMyDepHiddentroubleView = function () {
        $http({
            method: 'POST',
            url: '../HiddenTrouble/GetHiddenTroubleByDep'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                var datalist = ret.Data;
                var myChart = echarts.init(document.getElementById('htchart'));
                var option = {
                    title: {
                        show: false,
                        text: 'Referer of a Website',
                        subtext: 'Fake Data',
                        left: 'center'
                    },
                    tooltip: {
                        trigger: 'item'
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left',
                        show: false
                    },
                    series: [
                        {
                            label: {
                                alignTo: 'labelLine',
                                formatter: '{name|{b}}{c}项',
                                minMargin: 5,
                                edgeDistance: 3,
                                lineHeight: 15,
                                rich: {
                                    time: {
                                        fontSize: 10,
                                        color: '#999'
                                    }
                                }
                            },
                            name: '问题类型分布',
                            type: 'pie',
                            center: ['50%', '50%'],
                            radius: '50%',
                            data: datalist,
                            itemStyle: {
                                normal: {
                                    color: function (params) {
                                        var colorList = [
                                            '#FF6666', '#FFCC33','#00E5AB', '#0E5DA6',  '#0E5DA6', '#1177DC', '#FF6666'
                                        ];
                                        return colorList[params.dataIndex]
                                    }
                                }
                            },
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };
                myChart.setOption(option);

            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }


});